package com.levy.contronller.javaWeb.threadMasterWorker;


import java.util.Random;

public class Main {

    public static void main(String[] args) {
        int processors = Runtime.getRuntime().availableProcessors();
        System.out.println("我机器可用process数量:" + processors);
//        Master master = new Master(new Worker(), 50);
        Master master = new Master(new Worker(), processors);
        for (int i = 0; i < 100; i++) {
            Task t = new Task();
            t.setId(i);
            t.setName("任务_" + i);
            t.setPrice(new Random().nextInt(1000));
            master.submit(t);
        }

        master.execute();

        long start = System.currentTimeMillis();
        while (true) {
            if (master.isComplete()) {
                long end = System.currentTimeMillis() - start;
                Long l = master.gerResult();
                System.out.println(l);
                System.out.println("最终结果:" + l + "，耗时:" + end + "ms");
                break;
            }
        }
    }
}
